import React, {useState,useEffect} from 'react'
//主页样式
import index from './index.module.scss'
// 查询组件
import SearchHeader from './component/SearchHeader'
// 表格
import TableList from "./component/TableList";

// react-redux的东西
import store from "./redux/store";
import {Provider} from "react-redux";
import http from "../../../services/service";
import moment from "moment";

function InfoIndex () {
    //表格数据
    const [tableData, setTableData] = useState([]);
    const getTableData = () => {
        http.get("/yxx/rInfo").then(async (resp) => {
            resp.data.map(item=>{
                item.order_date = moment(item.order_date).format("YYYY-MM-DD");
                switch (item.order_status) {
                    case '0':
                        item.order_status = '待体检';
                        break;
                    case '1':
                        item.order_status = '待支付';
                        break;
                    case '2':
                        item.order_status = '已体检';
                        break;
                    case '3':
                        item.order_status = '已取消';
                        break;
                }
            });
            setTableData(resp.data)
        });
    };

    useEffect(() => {
        getTableData();
    }, []);

    //查询
    let searchTable = (value,selectValue,time)=>{
        if(selectValue==="5"){
            selectValue = ""
        }
        http.post(`/yxx/rSearchINfo`,{value,selectValue,time}).then(async (resp) => {
            resp.data.map(item=>{
                item.order_date = moment(item.order_date).format("YYYY-MM-DD");
                switch (item.order_status) {
                    case '0':
                        item.order_status = '待体检';
                        break;
                    case '1':
                        item.order_status = '待支付';
                        break;
                    case '2':
                        item.order_status = '已体检';
                        break;
                    case '3':
                        item.order_status = '已取消';
                        break;
                }
            });
            setTableData(resp.data)
        });
    };
    //修改状态


    return (
        <Provider store={store}>
            <div className={index.reserve_container}>
                <div className={index.search_title}><span>数据筛选</span></div>
                {/*搜索区域*/}
                <div className={index.search_content}>
                    <SearchHeader onChangeTable={searchTable}/>
                </div>
                <div className={index.table}>
                    <TableList tableData={tableData} getTableData={getTableData}/>
                </div>
            </div>
        </Provider>
    )
}
export default InfoIndex
